package net.xuele.learn.testClass;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.StampedLock;

/**
 * Created by GaoQingming on 2019/4/17 0017.
 */
public class testClass2 {

    public static volatile String status = "run";

    public static void main(String[] args) {

        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        scheduledExecutorService.schedule(() -> {
            System.out.println(Thread.currentThread().getName() + "退出！");
            status = "exit";
            System.out.println(status);
        },5L, TimeUnit.SECONDS);

        while ("run".equals(status)) {
            //System.out.println("当前是："+status);
            //System.out.println("123");
            if ("exit".equals(status)) {
                System.out.println(Thread.currentThread().getName() + "23333");
                break;
            }
        }
        System.out.println(Thread.currentThread().getName() + "over!");
        scheduledExecutorService.shutdown();


        StampedLock lock = new StampedLock();
        // 悲观读锁
        long readStamp = lock.readLock();
        try{

        } finally {
            lock.unlockRead(readStamp);
        }

        long writeStamp = lock.writeLock();

        try {

        } finally {
            lock.unlockWrite(writeStamp);
        }
    }
}
